package com.martini.satoken01.service.system;

import com.martini.satoken01.entity.SysMessageBoarder;
import com.martini.satoken01.mapper.system.SysMessageBoarderMapper;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author martini at 2021/12/27 21:54
 */
@Slf4j
public class DataSourceMessageBoarderServiceImpl implements MessageBoarderService {

    private final SysMessageBoarderMapper  sysMessageBoarderMapper;

    public DataSourceMessageBoarderServiceImpl(SysMessageBoarderMapper sysMessageBoarderMapper) {
        this.sysMessageBoarderMapper = sysMessageBoarderMapper;
    }

    @Override
    public int insertOne(SysMessageBoarder sysMessageBoarder) {
        return sysMessageBoarderMapper.insertUseGeneratedKeys(sysMessageBoarder);
    }

    @Override
    public int updateOne(SysMessageBoarder sysMessageBoarder) {
        return sysMessageBoarderMapper.updateByPrimaryKeySelective(sysMessageBoarder);
    }

    @Override
    public List<SysMessageBoarder> findByRect(int x1, int y1, int x2, int y2) {
        Example example = new Example(SysMessageBoarder.class);
        example.createCriteria()
            .andBetween("left", x1, x2)
            .andBetween("top", y1, y2)
            .andEqualTo("isDeleted", false);
        return sysMessageBoarderMapper.selectByExample(example);
    }

    @Override
    public SysMessageBoarder findById(Long id) {
        return sysMessageBoarderMapper.selectByPrimaryKey(id);
    }

    @Override
    public int softDeleteOneById(Long id) {
        SysMessageBoarder boarderBoForDelete = new SysMessageBoarder();
        boarderBoForDelete.setId(id).setIsDeleted(true);
        return sysMessageBoarderMapper.updateByPrimaryKeySelective(boarderBoForDelete);
    }

}
